import type { FormConfig } from '@/types/dynamic-form';

export const createRoleFormConfig = (isEdit: boolean = false): FormConfig => ({
  key: 'role-form',
  title: isEdit ? '编辑角色' : '新增角色',
  description: isEdit ? '修改角色信息' : '添加新的角色',
  layout: 'vertical',
  labelAlign: 'left',
  requiredMark: true,
  sections: [
    {
      key: 'basic',
      title: '基本信息',
      fields: [
        ...(isEdit ? [{
          key: 'id',
          label: 'ID',
          type: 'input',
          hidden: true,
        }] : []),
        {
          key: 'code',
          label: '角色编码',
          type: 'input',
          placeholder: '请输入角色编码',
          required: true,
          disabled: isEdit, // 编辑时禁用角色编码
          rules: [
            { required: true, message: '请输入角色编码' },
            { min: 2, max: 50, message: '角色编码长度在2-50个字符之间' },
            { pattern: /^[a-zA-Z0-9_]+$/, message: '角色编码只能包含字母、数字和下划线' },
          ],
        },
        {
          key: 'name',
          label: '角色名称',
          type: 'input',
          placeholder: '请输入角色名称',
          required: true,
          rules: [
            { required: true, message: '请输入角色名称' },
            { min: 2, max: 50, message: '角色名称长度在2-50个字符之间' },
          ],
        },
      ],
      col: 2,
      gutter: 16,
    },
  ],
  submitButton: {
    text: '确定',
    type: 'primary',
  },
  cancelButton: {
    text: '取消',
    type: 'default',
  },
});